package com.demo.controller;

import com.demo.pojo.User;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
public class Send {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("/hello")
    public String hello() {
        //唯一id
        String tag = UUID.randomUUID().toString();
        User user = new User();
        user.setName("123");
        rabbitTemplate.convertAndSend("hello-exchange","hello.java",user,new CorrelationData(tag));
        return "hello";
    }

    @RequestMapping("/hello1")
    public String hello1() {
        //唯一id
        String tag = UUID.randomUUID().toString();
        User user = new User();
        user.setName("123");
        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",user,new CorrelationData(tag));
        return "hello1";
    }
}
